package com.example.alibabanacosdiscoveryclient01.controller;

import com.example.alibabanacosdiscoveryclient01.entity.BookEntity;
import com.example.alibabanacosdiscoveryclient01.service.BookService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;

/**
 * @author:guoq
 * @date:2025/4/1
 * @descripion:
 */

@RestController
@RequestMapping("/ai")
@Tag(name = "mcp-server-stater应用")
public class MCPServerStarterController {
    @Resource
    private  ChatClient chatClient;


    @Autowired
    private BookService bookService;
    /**
     * 处理聊天请求，使用AI和MCP工具进行响应
     *
     * @param message 聊天请求
     * @return 包含AI回复的响应
     */
    @GetMapping("/mcp/chat")
    @Operation(summary = "mcp对话式应用")
    public String chat(String message) {
        // 使用流式API调用聊天
        String content = chatClient.prompt()
                .user(message)
                .call()
                .content();
        return  content;
    }
//    @GetMapping(value = "/mcp/books")
//    @Operation(summary = "获取图书列表")
//    public List<BookEntity> books() {
//        return bookService.list();
//    }

    @GetMapping("/mcp/initData")
    @Operation(summary = "初始化数据")
    public String init() {
        List<BookEntity> list = Arrays.asList(
                new BookEntity("Spring实战（第6版）", "编程", "Craig Walls",
                       "2022-01-15",  "9787115582247"),
                new BookEntity("深入理解Java虚拟机", "编程", "周志明",
                        "2019-12-01", "9787111641247"),
                new BookEntity("Java编程思想（第4版）", "编程", "Bruce Eckel",
                        "2007-06-01", "9787111213826"),
                new BookEntity("算法（第4版）", "计算机科学", "Robert Sedgewick",
                        "2012-10-01", "9787115293800"),
                new BookEntity("云原生架构", "架构设计", "张三",
                        "2023-03-15", "9781234567890"),
                new BookEntity("微服务设计模式", "架构设计", "张三",
                        "2021-08-20", "9789876543210"),
                new BookEntity("领域驱动设计", "架构设计", "Eric Evans",
                        "2010-04-10", "9787111214748"),
                new BookEntity("高性能MySQL", "数据库", "Baron Schwartz",
                        "2013-05-25", "9787111464747"),
                new BookEntity("Redis实战", "数据库", "Josiah L. Carlson",
                        "2015-09-30", "9787115419378"),
                new BookEntity("深入浅出Docker", "容器技术", "李四",
                        "2022-11-20", "9787123456789")
        );
        int i = bookService.batchInsert(list);
        return i + "";
    }

}

